package com.tentative.competition.web.controller.schedule.service;

import cn.hutool.core.util.BooleanUtil;
import com.tentative.competition.common.core.controller.BaseController;
import com.tentative.competition.common.core.domain.AjaxResult;
import com.tentative.competition.common.core.result.ApiResult;
import com.tentative.competition.common.core.result.PageResult;
import com.tentative.competition.common.model.schedule.param.ScheduleExamineParam;
import com.tentative.competition.common.model.schedule.resp.ScheduleExamineResp;
import com.tentative.competition.schedule.service.ScheduleExamineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther: Smile Huang
 * @date: 2023/6/22 17:21
 * @desc: 审核管理
 * @version: 2.0
 */
@Api(tags ="service-审批管理")
@RestController
@RequestMapping("/service/examine")
public class ExamineController extends BaseController {

    @Autowired
    private ScheduleExamineService examineService;

    /**
     * 获取审批列表
     * @return
     */
    @ApiOperation("获取审批列表")
    @GetMapping("/list")
    public ApiResult list(ScheduleExamineParam param) {
        PageResult<ScheduleExamineResp> iPage = examineService.selectExamineList(param);
        return ApiResult.ofPage(iPage.getContent(),iPage.getTotal());
    }

    @ApiOperation("审批通过")
    @PostMapping("/agree")
    public AjaxResult agree(@RequestBody ScheduleExamineParam param) {
        return BooleanUtil.isTrue(examineService.agree(param))?AjaxResult.success():AjaxResult.error();
    }

    @ApiOperation("审批拒绝")
    @PostMapping("/refuse")
    public AjaxResult refuse(@RequestBody ScheduleExamineParam param) {
        return BooleanUtil.isTrue(examineService.refuse(param))?AjaxResult.success():AjaxResult.error();
    }
}
